package com.atguigu.test2;

/**
 * @author 路飞
 * @date 2024/3/28 10:33
 * @description 3、编写方法实现：求某年某月某日是这一年的第几天
 * 提示：闰年（1）能被4整除不能被100整除（2）能被400整除
 */
public class Exer3 {
    public static void main(String[] args) {
        int year = 2024;
        int month = 3;
        int day = 28;
        int days = daysOfYear(year, month, day);
        System.out.println(year + "年" + month + "月" + day + "日是这一年的第" + days + "天");
    }

    /**
     * @description 闰年的2月份有29天
     */
    public static int daysOfYear(int year, int month, int day){
        int[] daysOfMonth = {31,28,31,30,31,30,31,31,30,31,30,31};
        if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
            daysOfMonth[1] = 29;
        }

        int days = 0;
        for (int i = 0; i < month - 1; i++) {
            days += daysOfMonth[i];
        }

        return days + day;
    }

}
